unit add_student_unit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, ImgList, data_module,
  StdCtrls, Mask, DBCtrls, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookupEdit,
  cxDBLookupEdit, cxDBLookupComboBox, DateUtils, cxSpinEdit, cxDBEdit;

type
  Tadd_student_form = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    fathername_edit: TEdit;
    ok_button: TButton;
    cancek_button: TButton;
    ImageList1: TImageList;
    Label6: TLabel;
    group_combo: TcxDBLookupComboBox;
    name_edit: TEdit;
    surname_edit: TEdit;
    study_type_combo: TcxLookupComboBox;
    Label7: TLabel;
    subgroup_spin_edit: TcxDBSpinEdit;
    Label8: TLabel;
    Label9: TLabel;
    school_combo: TcxLookupComboBox;
    Label10: TLabel;
    profile_combo: TcxLookupComboBox;
    begin_year_edit: TDBEdit;
    end_year_edit: TDBEdit;
    procedure set_edits(fio:string);
    procedure group_comboPropertiesChange(Sender: TObject);
    procedure cxLookupComboBox1PropertiesChange(Sender: TObject);
    procedure study_type_comboPropertiesChange(Sender: TObject);
    procedure school_comboPropertiesChange(Sender: TObject);
    procedure profile_comboPropertiesChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  add_student_form: Tadd_student_form;

implementation

{$R *.dfm}

procedure Tadd_student_form.cxLookupComboBox1PropertiesChange(Sender: TObject);
begin
  with data_mod.groups_query do
  begin
    ParamByName('id_study_type').Value:=study_type_combo.EditValue;
    ExecSQL;
  end;
end;

procedure Tadd_student_form.group_comboPropertiesChange(Sender: TObject);
var m:integer;
begin
  m:=MonthOf(Today);
  if group_combo.ItemIndex<>-1 then
  if m>9 then begin_year_edit.Text:=IntToStr(YearOf(Today)-data_mod.groups_query.Lookup('id_group',group_combo.EditValue,'group_course'))
  else begin_year_edit.Text:=IntToStr(YearOf(Today)-data_mod.groups_query.Lookup('id_group',group_combo.EditValue,'group_course')+1);
  end_year_edit.Text:=IntToStr(StrToInt(begin_year_edit.Text)+5);
end;

procedure Tadd_student_form.profile_comboPropertiesChange(Sender: TObject);
begin
  with data_mod.groups_query do
  begin
    ParamByName('id_profile').Value:=profile_combo.EditValue;
    ExecSQL;
  end;
end;

procedure Tadd_student_form.school_comboPropertiesChange(Sender: TObject);
begin
  with data_mod.profiles_query do
  begin
    ParamByName('id_school').Value:=school_combo.EditValue;
    ExecSQL;
  end;
end;

procedure Tadd_student_form.set_edits(fio: string);
var
  i,a,b: Integer;
begin
  a:=0;
  b:=0;
  i:=0;
  repeat
    inc(i);
    if (fio[i]=' ') and (a<>0) then b:=i;
    if (fio[i]=' ') and (a=0)  then a:=i;
  until (a<>0) and (b<>0);
  surname_edit.Text:=copy(fio,1,a-1);
  name_edit.Text:=copy(fio,a+1,b-a-1);
  fathername_edit.Text:=copy(fio,b+1,Length(fio)-b);
end;

procedure Tadd_student_form.study_type_comboPropertiesChange(Sender: TObject);
begin
  with data_mod.schools_query do
  begin
    ParamByName('id_study_type').Value:=study_type_combo.EditValue;
    ExecSQL;
  end;
end;

end.
